/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2006，所有权利保留。
 * 
 * 文件名：	BPermission.java
 * 模块说明：	
 * 修改历史：
 * 2006-8-20 - lxm - 创建。
 */
package com.hd123.rumba.user.biz;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.cartridge.ICartridgeMgr;
import com.hd123.rumba.cartridge.biz.SCartFunctionView;
import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.runtime.IPersistent;
import com.hd123.rumba.runtime.NamingMgr;
import com.hd123.rumba.runtime.biz.BVersionedPersistent;
import com.hd123.rumba.user.IPermission;

/**
 * 权限 | 业务层.维护 | 实体
 * 
 * @author lxm
 * 
 */
public class BPermission extends BVersionedPersistent {

  /** 代码 */
  private String code;

  /** 名称 */
  private String name;

  /** 构件包功能视图 */
  private SCartFunctionView cartFunctionView = null;

  /** 权限提供者 */
  private BPermissionProvider provider = null;

  /** 字段标题 */
  private String fieldCaption;

  /** 备注 */
  private String remark;

  /**
   * 从持久化对象赋值。
   * 
   * @param source
   * @throws BusinessException
   */
  public void readFrom(IPersistent source) throws BusinessException {
    if (source == null)
      return;
    super.readFrom(source);
    if (source instanceof IPermission) {
      this.code = ((IPermission) source).getCode();
      this.name = ((IPermission) source).getName();
      this.cartFunctionView = null;
      if (((IPermission) source).getCartFuncViewUuid() != null) {
        this.cartFunctionView = new SCartFunctionView();
        String cfvUuid = ((IPermission) source).getCartFuncViewUuid();
        ICartridgeMgr cartMgr = (ICartridgeMgr) NamingMgr.getInstance().lookupMgr(ICartridgeMgr.class);
        try {
          this.cartFunctionView.readFrom(cartMgr.getFunctionView(cfvUuid));
        } catch (HibernateException e) {
          throw new BusinessException(e.getMessage());
        }
      }
      this.provider = null;
      if (((IPermission) source).getProvider() != null) {
        this.provider = new BPermissionProvider();
        this.provider.readFrom(((IPermission) source).getProvider());
      }
      this.fieldCaption = ((IPermission) source).getFieldCaption();
      this.remark = ((IPermission) source).getRemark();
    }
  }

  public SCartFunctionView getCartFunctionView() {
    return cartFunctionView;
  }

  public void setCartFunctionView(SCartFunctionView cartFunctionView) {
    this.cartFunctionView = cartFunctionView;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getFieldCaption() {
    return fieldCaption;
  }

  public void setFieldCaption(String fieldCaption) {
    this.fieldCaption = fieldCaption;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public BPermissionProvider getProvider() {
    return provider;
  }

  public void setProvider(BPermissionProvider provider) {
    this.provider = provider;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

}
